﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace POB
{
    class ResulutionManager
    {
        SpriteBatch spriteBatch;
        Rectangle realScreen;
        Rectangle virtualScreen;
        Texture2D pixel;

        Matrix result;

        public Matrix Matrix { get { return result; } }

        float yMove;

        public ResulutionManager(SpriteBatch SpriteBatch, GraphicsDevice Device, Rectangle RealScreen, Rectangle VirtualScreen)
        {
            spriteBatch = SpriteBatch;
            realScreen = RealScreen;
            virtualScreen = VirtualScreen;
            pixel = new Texture2D(Device, 2, 2);
            Color[] color = { Color.White, Color.White, Color.White, Color.White };
            pixel.SetData<Color>(color);

            //Scalefaktor ausrechnen...
            // Da wir das Breiteste aller Formate gewählt haben, können wir uns sicher sein, dass wenn die Breite passt, auch der Rest passt :)
            float scale = (float)realScreen.Width / (float)virtualScreen.Width;

            //Y-Verschiebung ausrechen.
            //Wie viel vom bildschrim wäre frei?
            float space = realScreen.Height - virtualScreen.Height * scale;
            yMove = space / 2;

            result = Matrix.CreateScale(scale, scale, 0f) * Matrix.CreateTranslation(new Vector3(0f, yMove, 0f));

			//result = new Matrix();

			//result += Matrix.CreateScale(scale);
			//Vector3 trans = result.Translation;
			//trans.Y = yMove;
			//result.Translation = trans;
        }

        public void Draw()
        {
            spriteBatch.Begin();
            spriteBatch.Draw(pixel, new Rectangle(0, 0, realScreen.Width, (int)yMove), Color.Black);
            spriteBatch.Draw(pixel, new Rectangle(0, realScreen.Height - (int)yMove, realScreen.Width, (int)yMove), Color.Black);
            spriteBatch.End();
        }

    }
}
